package com.dcits.electronic_account.mapper;

import com.dcits.electronic_account.bean.BankAccount;
import com.dcits.electronic_account.bean.VirtualAccount;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;


/**
 * @author: YHC
 * @Date: 2022/6/25
 */
@Mapper
public interface RechargeMapper {

    //根据用户id查询用户
    @Select("select user_id,user_name,login_pwd,pay_pwd,id_number,phone,name,balance from electronic_account.virtual_account where user_id=#{userId}")
    VirtualAccount searchVirByUserId(Integer userId);

    //根据银行卡号查询银行卡
    @Select("select id,bank_card_number,bank,balance,id_number,phone,name from electronic_account.bank_account where bank_card_number=#{cardNumber}")
    BankAccount searchBankByNumber(String cardNumber);

    //更新银行卡金额
    @Update("update electronic_account.bank_account set balance=#{balance} where bank_card_number=#{cardNumber}")
    int updateCardBalance(@Param("balance") BigDecimal balance,@Param("cardNumber") String cardNumber);

    //更新账户金额
    @Update("update electronic_account.virtual_account set balance=#{balance} where user_id=#{userId}")
    int updateUserBalance(@Param("balance") BigDecimal balance,@Param("userId") Integer userId);
}
